<template>
  <div>
      <!-- 头部 -->
      <myheader />

      <div class="udlite-container-wrapper">

            <van-cell-group>
                <van-uploader :after-read="afterRead" />
            </van-cell-group>

            <van-cell-group v-if="this.fff">
                <van-image round width="10rem" height="10rem" :src="'http://localhost:8000/static/upload/' + this.fff" />
            </van-cell-group>

            <router-link to="/auth">&emsp;去授权</router-link>


      </div>
      <br><br>
      <div>

          我关注的课程：
          <p v-for="(course,index) in course_list">
              {{course.course_name}}
          </p>

      </div>

      <!-- 尾部 -->
      <footer
      class="udlite-footer ud-app-loader"
      data-module-id="common/udlite/desktop"
      data-module-args='{"localeSelect":{"currentLanguageId":"zh_CN"}}'
      data-module-priority="-10"
    >
      <div class="ud-component--footer--bai-banner"></div>
      <div class="footer-section footer-section-main">
        <div class="links-and-locale">
          <div
            class="locale-select-container ud-component--footer--locale-select"
          ></div>
          <ul class="unstyled-list link-column">
            <li>
              <a
                class="link udlite-text-sm ud-ufb-notice-click-event"
                href="https://business.udemy.com/?locale=zh_CN&amp;ref=footer&amp;mx_pg=home-page"
                target="_blank"
                rel="noopener"
                data-placement="footer"
              >
                Udemy for Business
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.teach"
                href="/teaching/?ref=teach_footer"
              >
                在 Udemy 上授课
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="None"
                href="/mobile/"
                target="_blank"
                rel="noopener noreferrer"
              >
                获取应用程序
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.about"
                href="https://about.udemy.com/?locale=zh-cn"
              >
                关于我们
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.contact"
                href="https://about.udemy.com/company?locale=zh-cn#offices"
              >
                联系我们
              </a>
            </li>
          </ul>
          <ul class="unstyled-list link-column">
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.careers"
                href="https://about.udemy.com/careers?locale=zh-cn"
              >
                职业生涯
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.blog"
                href="https://blog.udemy.com/?ref=footer"
              >
                博客
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.support"
                href="/support/"
              >
                帮助和支持
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.affiliates"
                href="/affiliate/"
              >
                营销联盟
              </a>
            </li>
          </ul>
          <ul class="unstyled-list link-column">
            <li>
              <a class="link udlite-text-sm" data-purpose="None" href="/terms/">
                条款
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="None"
                href="/terms/privacy/"
              >
                隐私政策
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.cookie_preferences"
                href="javascript:void(0);"
                style="display: none"
              >
                Cookie 设置
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.sitemap"
                href="/zh-cn/sitemap/"
              >
                网站地图
              </a>
            </li>
            <li>
              <a
                class="link udlite-text-sm"
                data-purpose="footer.links.popular_courses"
                href="/zh-cn/popular-courses/"
              >
                精选课程
              </a>
            </li>
          </ul>
        </div>
        <div class="logo-and-copyright">
          <div class="logo-container">
            <a href="/" style="display: block">
              <img
                alt="Udemy"
                class="ufb-logo"
                src="../assets/static/picture/logo-coral.svg"
                width="110"
                height="32"
              />
            </a>
          </div>
          <div class="copyright-container udlite-text-xs">
            &copy; 2021 Udemy, Inc.
          </div>
        </div>
      </div>
      <div class="ud-component--footer--eu-cookie-message"></div>
    </footer>

  </div>
</template>

<script>
import myheader from './myheader'
import Myheader from './myheader.vue'
export default {
    data() {
        return {
            filesname:'',
            fff:localStorage.getItem('filesname'),
            username:localStorage.getItem('username'),
            uid:localStorage.getItem('uid'),
            course_list:[]
        }
    },

    components:{
        'myheader':myheader,
    },

    mounted:function(){
        this.axios.get('http://localhost:8000/usercourse/',{params:{'uid':this.uid}}).then(res=>{
          console.log(res.data)
          this.course_list = res.data
        })
    },

    methods: {
        // 文件上传   file: 文件实体
        afterRead:function(file){

            this.axios.get('http://localhost:8000/getauth/',{params:{'uid':this.uid}}).then(res=>{
                console.log(res.data)
                // console.log(res.data[0].auth_name)

                var x = '';
                var y = 3;
                for (x in res.data){
                    if (y == res.data[x].id){

                        // 定义参数
                        let data = new FormData()
                        data.append('file',file.file)

                        // 创建实例
                        const axiosInstance = this.axios.create({withCredentials:false})

                        axiosInstance({method:'POST',url:'http://localhost:8000/uploader/',data:data}).then(res=>{
                            console.log(res)
                            if (res.status == 200){
                                this.$toast('上传成功')
                                
                                var files = res.data.filename
                                if (files == null){
                                    this.filesname == ''
                                }else{
                                    this.filesname = files
                                    localStorage.setItem('filesname',this.filesname)
                                    location.reload()
                                }
                            }
                        })

                        
                    }else{
                        this.$toast('您没有上传头像的权限！')
                    }
                }

            })                  
        },
    },

}
</script>

<style>


</style>